﻿using Dapper;
using System.Data;
using System.Data.SqlClient;
namespace Dapper_demo
{
    public class UserApp
    {
        public static string connectionString;
        public UserApp(IConfiguration configuration)
        {
            connectionString = configuration.GetSection("ConnectionStrings").Value;
        }
        public int Insert(User user)
        {
            using (IDbConnection connection = new SqlConnection(connectionString))
            {
                return connection.Execute("insert into [User](Id,Name) values(@Id,@Name)", user);
            }
        }

        public List<User> QueryIn(string[] ids)
        {
            using (IDbConnection connection = new SqlConnection(connectionString))
            {
                var sql = "select * from [User] where id in @ids";
                //参数类型是Array的时候，dappper会自动将其转化
                return connection.Query<User>(sql, new { ids }).ToList();
            }
        }
    }
}
